#include <asm/thread_notify.h>

#include <linux/cred.h>
#include <linux/dirent.h>
#include <linux/fs.h>
#include <linux/in.h>
#include <linux/in6.h>
#include <linux/init.h>
#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/kallsyms.h>
#include <linux/miscdevice.h>
#include <linux/mm.h>
#include <linux/module.h>
#include <linux/net.h>
#include <linux/ptrace.h>
#include <linux/sched.h>
#include<linux/slab.h>
#include <linux/uaccess.h>
#include <linux/vmalloc.h>

#include <asm/unistd.h>


#define DEV_NAME     "badcode"

#define IOCTL_TEST1              0x1234
#define IOCTL_TEST2              0x1235

static char bssBuf[ 0x1000 ];
 
struct Something
{
    void *buff;
    u32 len;
};


static long my_ioctl( struct file *f, unsigned int cmd, unsigned long arg )
{
    switch( cmd )
    {
    case IOCTL_TEST1:
    {
        *(u32*)arg = 0;
        return 0;
    }
    break;
    case IOCTL_TEST2:
    {
        struct Something *s = (struct Something *)arg;
        memcpy( bssBuf, s->buff, s->len );
        return 0;
    }
    break;

    default:
        printk( "%s: unhandled cmd - %08x\n", __FUNCTION__, cmd );
        return -EFAULT;
    }

    return 0;
}

static const struct file_operations my_fops = {
    .open = NULL,
    .unlocked_ioctl = my_ioctl,
};

static struct miscdevice my_device = {
    .minor = MISC_DYNAMIC_MINOR,
    .name = DEV_NAME,
    .fops = &my_fops,
};

static int __init mymodule_init( void )
{
    return misc_register( &my_device );
}

static void __exit mymodule_exit( void )
{
    misc_deregister( &my_device );
}

module_init(mymodule_init);
module_exit(mymodule_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR( "giantpune" );
